package com.bot.pms.common.config.dateConverter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * LocalDate转换器，用于转换RequestParam和PathVariable参数
 */
public class LocalDateConverter implements Converter<String, LocalDate> {
    private final String DEFAULT_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    @Override
    public LocalDate convert(String source) {
        if (StringUtils.isEmpty(source)) {
            return null;
        }
        return LocalDate.parse(source, DateTimeFormatter.ofPattern(DEFAULT_DATETIME_FORMAT));
    }
}
